/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Fines {
    public static boolean insertFine(Entity.Fine fin){
        try {
            String sql = "insert into tblFine values(?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, fin.get_StudentID());
            ps.setString(2, fin.get_SubjectID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Fines.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }       
    }
    public static boolean updateFine(Entity.Fine fin){
        try {
            String sql = "update tblFine set StudentID=?, SubjectID=? where FineID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, fin.get_StudentID());
            ps.setString(2, fin.get_SubjectID());
            ps.setInt(3, fin.get_FineID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Fines.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }        
    }
    
    public static void deleteFine(int intFineID){
        try {
            String sql = "delete from tblFine where FineID = " + intFineID;
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Fines.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
}
